package servicesImp.business;

import base.IBaseMapperWithoutBLOBs;
import base.IBaseServicesWithoutBLOBsImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import services.business.BusinessInfoServices;
import services.business.BusinessMajorServices;
import util.key.IDFactory;
import wt.dao.business.BusinessInfoMapper;
import wt.entity.business.BusinessInfo;
import wt.entity.business.BusinessInfoExample;
import wt.entity.business.BusinessMajor;
import wt.staticData.TableName;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2017/10/14.
 */
@Service
public class BusinessInfoServicesImp extends IBaseServicesWithoutBLOBsImpl< BusinessInfo, BusinessInfoExample> implements BusinessInfoServices {
    @Autowired
    BusinessInfoMapper businessInfoMapper;
    @Autowired
    BusinessMajorServices businessMajorServices;

    @Override
    public IBaseMapperWithoutBLOBs<BusinessInfo, BusinessInfoExample> getMapper() {
        return this.businessInfoMapper;
    }



    @Override
    public String getTableName() {
        return TableName.BUS_BUSINESS_INFO;
    }


    public List<BusinessInfo> select(String observerName, String managerName, String inspectorName, Date checkStartTime, Date checkEndTime, String companyName, String productName, Short observerIsReport, Short observerIsAssess, Short managerIsAssess, Short companyIsAssess) throws Exception {
        return businessInfoMapper.select(observerName, managerName, inspectorName, checkStartTime, checkEndTime, companyName, productName, observerIsReport, observerIsAssess, managerIsAssess, companyIsAssess);
    }


    public BusinessInfo selectByBusinessCode(String businessCode) throws Exception {
        BusinessInfoExample businessInfoExample = new BusinessInfoExample();
        businessInfoExample.createCriteria().andBusinessCodeEqualTo(businessCode);
        List<BusinessInfo> businessInfoList = selectByExample(businessInfoExample);
        if (businessInfoList.isEmpty()) {
            return null;
        } else {
            return businessInfoList.get(0);
        }
    }

    @Transactional
    public void insertSelective(BusinessInfo businessInfo, List<String> majorNumList) throws Exception {
        getCurrentProxy().insertSelective(businessInfo);

        BusinessMajor businessMajor=new BusinessMajor();
        for (String s:majorNumList) {
            businessMajor.setId(IDFactory.getSnowflakeId());
            businessMajor.setBusinessId(businessInfo.getId());
            businessMajor.setMajorNum(s);
            businessMajorServices.insertSelective(businessMajor);
        }

    }
}
